package com.kfm.jdbc.day0406;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class GroupReceiver2 {

    public static void main(String[] args) {
        try {
            MulticastSocket multicastSocket = new MulticastSocket(8888);
            InetAddress address = InetAddress.getByName("224.0.1.0");
            multicastSocket.joinGroup(address);

            byte[] buf = new byte[1024];
            DatagramPacket packet = new DatagramPacket(buf, buf.length);

            multicastSocket.receive(packet);

            String msg = new String(packet.getData(), 0, packet.getLength());
            System.out.println(msg);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
